#include <ObjectInspector.h>
ObjectInspector::ObjectInspector( QWidget *parent /*= 0*/ ) : QWidget(parent)
{
	m_treeView = new QTreeView(this);
    m_model = new ObjectInspectorModel;
	m_treeView->setModel(m_model);
    m_treeView->setSelectionMode(QAbstractItemView::SelectionMode::ExtendedSelection);
    //连接信号槽
    QItemSelectionModel* select_model = m_treeView->selectionModel();
    QObject::connect(select_model, SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex &)), m_model, SLOT(slotCurrentChanged ( const QModelIndex &, const QModelIndex &)));
    QObject::connect(select_model, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )), m_model, SLOT(slotSelectionChanged ( const QItemSelection & , const QItemSelection &)));
}

ObjectInspector::~ObjectInspector()
{

}
QTreeView * ObjectInspector::getTreeView()
{
	return m_treeView;
}

void ObjectInspector::replaceModel(ObjectInspectorModel *model )
{
	if (model != NULL)
	{
		m_treeView->setModel(model);
		delete m_model;
		m_model = model;

        QItemSelectionModel* select_model = m_treeView->selectionModel();
        QObject::connect(select_model, SIGNAL(currentChanged ( const QModelIndex &, const QModelIndex &)), m_model, SLOT(slotCurrentChanged ( const QModelIndex &, const QModelIndex &)));

    }
}

void ObjectInspector::addDirector(QSharedPointer<ObjectInspectorDirector> director)
{
    m_model->addDirector(director);
}

void ObjectInspector::rebuild()
{
    m_model->rebuild();
}

void ObjectInspector::refresh()
{
    m_model->refresh();
}

void ObjectInspector::clear()
{
    m_model->clear();
}

ObjectInspectorModel *ObjectInspector::getObjectInspectorModel()
{
    return m_model;
}
